<template>
	<view class="">
		<web-view :src="src" v-if="src" @message="monitorMessage"></web-view>
	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/auth'
	import {
		getSystemHeightInfo
	} from "@/utils/common.js"

	export default {
		data() {
			return {
				src: ''
			}
		},
		onLoad(option) {
			let type = 'app'
			// #ifdef MP-WEIXIN
			type = 'wx'
			// #endif
			const systemInfo = getSystemHeightInfo()
			this.src = this.$config.SHARE_URL + `safeMonitor?token=${getToken()}&page=monitoring&projectId=${uni.getStorageSync("isOwner")}&type=${type}&videoType=0&systemInfo=${JSON.stringify(systemInfo)}&time=${Date.now()}`
			// this.src = `http://192.168.20.53:8800/#/safeMonitor?token=${getToken()}&page=monitoring&projectId=${uni.getStorageSync("isOwner")}&type=${type}&videoType=0&systemInfo=${JSON.stringify(systemInfo)}&time=${Date.now()}`
			// this.src = `http://192.168.20.153:8800/#/safeMonitor?token=${getToken()}&page=monitoring&projectId=${uni.getStorageSync("isOwner")}&type=${type}&systemInfo=${JSON.stringify(systemInfo)}`
			// this.src = `https://cdsa.stec.sh.cn/1cdsa-link/#/safeMonitor?token=${getToken()}&page=monitoring&projectId=${uni.getStorageSync("isOwner")}&type=${type}&systemInfo=${JSON.stringify(systemInfo)}`
			console.log(this.src,'.src');
		},
		methods: {
			/** 监听消息 */
			monitorMessage(data) {
				// #ifdef APP-PLUS
				const message = data.detail.data
				if (Array.isArray(message) && message.length && message[0].type === 'saveImage') {
					const base64 = message[0].value;
					const bitmap = new plus.nativeObj.Bitmap("test");
					bitmap.loadBase64Data(base64, () => {
						bitmap.save("_doc/test.png", {}, data => {
							uni.saveImageToPhotosAlbum({
								filePath: data.target,
								success: () => {
									uni.showToast({
										title: "保存成功",
										icon: "none"
									})
								},
								fail: (error) => {
									uni.showToast({
										title: "保存失败",
										icon: "none"
									})
								},
							})
							bitmap.clear();
						}, () => {
							uni.showToast({
								title: "保存失败",
								icon: "none"
							})
							bitmap.clear();
						});
					}, () => {
						uni.showToast({
							title: "保存失败",
							icon: "none"
						})
						bitmap.clear();
					});
				}
				// #endif
			},
		}
	}
</script>

<style>
</style>